package edu.whu.webgis.entity;

import edu.whu.webgis.utils.ImgUtil;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;

@Data
@NoArgsConstructor
public class VPosting {
    Integer id;
    List<String> pics;
    String content;
    Integer likes;
    String uid;
    String author;
    List<String> category;
    String title;

    public VPosting(Posting posting) {
        this.setId(posting.getId());
        this.setContent(posting.getContent());
        this.setLikes(posting.getLikes());
        this.setUid(posting.getUid());
        this.setAuthor(posting.getAuthor());
        this.setTitle(posting.getTitle());
        this.setCategory(Arrays.stream(posting.getCategory().split(" ")).toList());
        String[] strs = posting.getPics().split(" ");
        List<String> pics = new ArrayList<>(strs.length);
        for (String str: strs){
            pics.add(ImgUtil.getBase64Jpg(str));  ;
        }
        this.setPics(pics);
    }
}
